package com.starview.star.compiler.canonical.compile;

import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodNode;

import com.starview.star.code.repository.CodeCatalog;
import com.starview.star.compiler.ErrorReport;
import com.starview.star.compiler.cafe.compile.CafeDictionary;
import com.starview.star.compiler.cafe.compile.HWM;
import com.starview.star.compiler.cafe.compile.LiveMap;
import com.starview.star.compiler.cafe.compile.Sense;

public class ConditionContext extends CompileContext
{

  private final Sense sense;
  private final LabelNode lf;
  private final LabelNode lx;

  public ConditionContext(HWM hwm, ErrorReport errors, ClassNode klass, MethodNode mtd, Continue cont,
      CafeDictionary dict, CodeCatalog bldCat, Sense sense, LabelNode lf, LabelNode lx, LiveMap localMap,
      FrameState frame)
  {
    super(hwm, errors, klass, mtd, cont, dict, bldCat, localMap, frame);
    this.sense = sense;
    this.lf = lf;
    this.lx = lx;
  }

  public LabelNode getLf()
  {
    return lf;
  }

  public LabelNode getLx()
  {
    return lx;
  }

  public Sense getSense()
  {
    return sense;
  }

  public static ConditionContext fork(CompileContext cxt, Sense sense, LabelNode lf, LabelNode lx)
  {
    return new ConditionContext(cxt.hwm, cxt.errors, cxt.klass, cxt.mtd, cxt.cont, cxt.dict, cxt.bldCat, sense, lf, lx,
        cxt.getLocalMap(), cxt.getFrame());
  }

  public ConditionContext fork(Sense sense, LabelNode lf, LabelNode lx)
  {
    return new ConditionContext(hwm, errors, klass, mtd, cont, dict, bldCat, sense, lf, lx, getLocalMap(), frame);
  }

  @Override
  public CompileContext fork(Continue cont)
  {
    return new ConditionContext(hwm, errors, klass, mtd, cont, dict, bldCat, sense, lf, lx, getLocalMap(), frame);
  }

  @Override
  public CompileContext fork(CafeDictionary dict)
  {
    return new ConditionContext(hwm, errors, klass, mtd, cont, dict, bldCat, sense, lf, lx, getLocalMap(), frame);
  }
}
